import * as React from 'react';
import { Button } from 'antd';
import {  ButtonType } from 'antd/lib/button/button';

interface IAppProps {
    name?: string,
    onClick: any;
    type?: ButtonType;
}


class IButton extends React.Component<IAppProps, {}> {
    state = {
        isLoading: false
    }
    public render() {
        const { name, type } = this.props;
        const { isLoading } = this.state;
        return (
            <div className="center">
                <Button type={type}   onClick={this.handleSubmit} htmlType="submit" loading={isLoading} className="login-form-button">
                    {name}
                </Button>
            </div>
        );
    }

    private handleSubmit = async (e: any) => {
        e.preventDefault();
        this.setState({
            isLoading: true,
        })
        await new Promise((resolve) => setTimeout(resolve, 1000));
        try {
            await this.props.onClick();
        } catch (error) {
        }
       
        this.setState({
            isLoading: false,
        })
    }
}


export default IButton;